package com.itheima.threadsafetydemo;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Account {
    private String cardId;
    private int money = 0;

    public void draw(int drawMoney){
        if(money >= drawMoney){
            // 模拟网络延迟
            try {
                Thread.currentThread().sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // 模拟取款
            money -= drawMoney;
            System.out.println(Thread.currentThread().getName() + "取款成功，余额为：" + money);
        }else{
            System.out.println(Thread.currentThread().getName() + "取款失败，余额不足");
        }
    }
}
